#!/bin/sh
# git hook to ensure code style
# cp scripts/pre-commit .git/hooks/

which >/dev/null pep8 || (echo "please install pep8"; exit 1)
files=$(git diff --name-only --staged --diff-filter=ACMRTUXB | egrep "*.py$")

if test -n "$files"; then
  pep8 --max-line-length=100 $files
  res=$?
  if [ $res -ne 0 ]; then
    echo
    autopep8 --max-line-length=100 --diff $files
    echo
    echo "To fix run: autopep8 --max-line-length=100 -i $files"
  fi
  exit $res
fi
